import 'package:lx_widgets_library/extension/enum_ex.dart';

// 车辆蓝牙连接状态
enum VehicleBleConnectState {
  /// 已断开
  disconnected(0, "Disconnected"),

  // 连接中
  connecting(1, "Connecting"),

  /// 已连接
  connected(2, "Connected"),

  /// 蓝牙未开启
  bluetoothOff(3, "BluetoothOff"),

  /// 未开启蓝牙权限
  bluetoothUnauthorized(4, "BluetoothUnauthorized"),

  /// 未开启蓝牙扫描权限
  bluetoothScanPermissionOff(5, "BluetoothScanPermissionOff"),

  /// 未开启蓝牙连接权限
  bluetoothConnectPermissionOff(6, "BluetoothConnectPermissionOff"),

  /// 未开启位置权限
  locationPermissionOff(7, "LocationPermissionOff"),

  /// 未开启位置服务
  locationServiceOff(8, "LocationServiceOff");

  final int rawValue;
  final String name;
  const VehicleBleConnectState(this.rawValue, this.name);
  // 通过 title 获取枚举类型
  static VehicleBleConnectState? getTypeByTitle(String title) =>
      VehicleBleConnectState.values
          .firstWhereOrNull((activity) => activity.name == title);
  // 通过 rawValue 获取枚举类型
  static VehicleBleConnectState? getTypeByNum(int rawValue) =>
      VehicleBleConnectState.values
          .firstWhereOrNull((activity) => activity.rawValue == rawValue);
  // 通过 rawValue 获取 title
  static String? getValue(int rawValue) => VehicleBleConnectState.values
      .firstWhereOrNull((activity) => activity.rawValue == rawValue)
      ?.name;
}